let config = require('config');
let log4js = require('log4js');
let path = require('path');
log4js.configure(config.get('log4js'));
let origin = log4js.getLogger;
let cwd = process.cwd();
log4js.getLogger = function(category) {
	if (category.lastIndexOf('.js')) {
		category = category.replace(cwd + '/', '').split(path.sep).join('.');
		category = category.substr(0, category.length - 3);
	}
	return origin.call(log4js, category);
};

function getLogger(file) {
	return log4js.getLogger(file)
}

function hrTime() {
	let t = process.hrtime();

	return t[0] * 1000 + parseInt(t[1] / 1000000);
}

function sleep(time) {
	return new Promise(function(resolve) {
		setTimeout(resolve, time)
	})
}

module.exports = { hrTime, getLogger, sleep }
